﻿/**
* Description 版权所有2008@qz http://www.newpub.cn
* @author lbynet
* @version 0.1
* @discription:右键版权类; QcontextMenu.getInstance().Data=siteCommon.Data;
*/
package com.lbynet.util{
	
	import flash.events.*;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuBuiltInItems;
	import flash.ui.ContextMenuItem;
	
	import flash.text.TextField;
	
	public class QcontextMenu{
		
		private var customItems:Array;
		private var Qmenu:ContextMenu;
		private static var Instance:QcontextMenu = new QcontextMenu();
		
		public function QcontextMenu () {
			if(Instance!=null){
				throw new Error("单件")
			}
		}
		
		/*
		 * 单件类的实例 
		*/
		public static function getInstance():QcontextMenu{
			return Instance;
		}
		
		public function setStaticObjectNull():void{
		    Instance = null;
		}
		
		
		
		private var content_txt:TextField;
		
		/**
		* 文本对象 右键功能.
		* @param
		*/
		public function bulidControl(_text:TextField):void {
			
			content_txt = _text;
			
			var customItems:Array;
			var ControlMenu:ContextMenu = new ContextMenu();
			ControlMenu.hideBuiltInItems();
			
			var menuItem:ContextMenuItem = new ContextMenuItem ("清空聊天信息");
			menuItem.separatorBefore = true;
			ControlMenu.customItems.push (menuItem);
			menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, clearHandler);
			
			menuItem = new ContextMenuItem ("返回顶部");
			menuItem.separatorBefore = true;
			ControlMenu.customItems.push (menuItem);
			menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, topHandler);
			
			menuItem = new ContextMenuItem ("回到底部");
			ControlMenu.customItems.push (menuItem);
			menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, bottomHandler);
			
			content_txt.contextMenu = ControlMenu;
			//ControlMenu.addEventListener(ContextMenuEvent.MENU_SELECT, controlHandler);
			
		}
		
		/*
		 * 清除文本 
		*/
		private function clearHandler (event:Event):void {
			
			content_txt.text = "";
		}
		
		private function topHandler (event:Event):void {
			
			content_txt.scrollV = 1;
		}
		
		private function bottomHandler (event:Event):void {
			
			content_txt.scrollV = content_txt.maxScrollV;
		}
		
		
	}
}
